package cn.xiuxius.embedded.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.experimental.Accessors;

@Accessors(chain = true)
public class LHFlashOptionType extends AbstractFlashOptionType<LHType> {


    public LHFlashOptionType(LHType value, String cmdValue, boolean isDefault) {
        super(value, cmdValue, isDefault);
    }

    public static final LHFlashOptionType DEFAULT = new LHFlashOptionType(LHType.DEFAULT, "default", true);

    @JsonCreator
    public static LHFlashOptionType from(Object val) {
        if (val instanceof String s) {
            if ("DEFAULT".equalsIgnoreCase(s)) {
                return DEFAULT;
            }
            if ("LOW".equalsIgnoreCase(s)) {
                return new LHFlashOptionType(LHType.LOW, LHType.LOW.getValue(), false);
            }
            if ("HIGH".equalsIgnoreCase(s)) {
                return new LHFlashOptionType(LHType.HIGH, LHType.HIGH.getValue(), true);
            }
        }
        throw new IllegalArgumentException("Unsupported Low&High Type input: " + val);
    }

    @Override
    public String getCmdValue() {
        return getValue().getValue();
    }


    @Override
    public boolean isDefault() {
        return DEFAULT.equals(this);
    }

}
